//
//  ECMemberSourceTableViewCell.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/10/23.
//  Copyright © 2018年 Mac. All rights reserved.
//

#import "ECMemberSourceTableViewCell.h"

@interface ECMemberSourceTableViewCell()

@property (nonatomic,strong) CAShapeLayer * bottomLine;

@property (nonatomic,strong) UIButton * changeStatuBT;

@end

@implementation ECMemberSourceTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)prepareForReuse {
    [super prepareForReuse];
    self.isForbid = NO;
    self.titleLB.text = nil;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (!self.bottomLine) {
        self.bottomLine = [CAShapeLayer layer];
        [self.contentView.layer addSublayer:self.bottomLine];
        self.bottomLine.borderColor = [UIColor colorWithRed:242/255.0f green:242/255.0f blue:242/255.0f alpha:1].CGColor;
        self.bottomLine.borderWidth = 0.25 * PX_RELATIVE375;
    }
    self.bottomLine.frame = CGRectMake(12 * PX_RELATIVE375, self.contentView.height - 0.5 * PX_RELATIVE375, self.contentView.width - 24 * PX_RELATIVE375, 0.5 * PX_RELATIVE375);
}

- (void)setupUI {
    __weak typeof(self) weakSelf = self;
    self.changeStatuBT = [UIButton buttonWithType:UIButtonTypeCustom];
    self.changeStatuBT.clipsToBounds = YES;
    self.changeStatuBT.layer.cornerRadius = 3 * PX_RELATIVE375;
    self.changeStatuBT.titleLabel.font = ECFONT(12*PX_RELATIVE375);
    [self.changeStatuBT setTitle:@"启用" forState:UIControlStateNormal];
    [self.changeStatuBT setTitleColor:[UIColor colorWithRed:65/255.0f green:217/255.0f blue:90/255.0f alpha:1] forState:UIControlStateNormal];
    [self.changeStatuBT setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:217/255.0f green:255/255.0f blue:217/255.0f alpha:1]] forState:UIControlStateNormal];
    
    [self.changeStatuBT setTitle:@"禁用" forState:UIControlStateSelected];
    [self.changeStatuBT setTitleColor:[UIColor colorWithRed:255/255.0f green:51/255.0f blue:51/255.0f alpha:1] forState:UIControlStateSelected];
    [self.changeStatuBT setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:251/255.0f green:234/255.0f blue:234/255.0f alpha:1]] forState:UIControlStateSelected];
    
    [self.contentView addSubview:self.changeStatuBT];
    [self.changeStatuBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.contentView);
        make.width.mas_equalTo(50 * PX_RELATIVE375);
        make.height.mas_equalTo(20 * PX_RELATIVE375);
        make.right.mas_equalTo(weakSelf.contentView).mas_offset(-12*PX_RELATIVE375);
    }];
    
    self.titleLB = [UILabel new];
    self.titleLB.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1];
    self.titleLB.font = ECFONT(16*PX_RELATIVE375);
    [self.contentView addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.contentView);
        make.left.mas_equalTo(weakSelf.contentView).mas_offset(12 * PX_RELATIVE375);
        make.right.mas_lessThanOrEqualTo(weakSelf.changeStatuBT.mas_left).mas_offset(-10 * PX_RELATIVE375);
    }];
}

- (void)setIsForbid:(BOOL)isForbid {
    _isForbid = isForbid;
    if (_isForbid) {
        self.changeStatuBT.selected = YES;
    }else {
        self.changeStatuBT.selected = NO;
    }
}

@end
